<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <title>用户管理</title>
    <%@ include file="/WEB-INF/views/modules/commons/head.jsp" %>
    <%--多选css--%>
    <link rel="stylesheet" href="<s:url value="/assets/web/js/multiSelect/css/fselect.css"></s:url>">
    <!-- header -->
    <%@ include file="/WEB-INF/views/include/header.jsp" %>
    <style>
        #gridTable tr td {
            text-align: center;
        }

        #gview_gridTable thead tr th .ui-jqgrid-sortable {
            text-align: center;
        }

        /*转成省略号*/
        /*.ui-jqgrid tr.jqgrow td { text-overflow : ellipsis; }*/
        .ui-jqgrid tr.jqgrow td {
            white-space: normal !important;
            height: 25px;
            line-height: 25px;
            vertical-align: text-top;

        }

        .nav {
            margin-left: 0;
        }

        #gview_gridTable .ui-jqgrid-bdiv {
            max-height: 450px;
        !important;
        }

        .nav > li > a:focus, .nav > li > a:hover {
            text-decoration: none;
            background-color: #33CCFF !important;
        }

        #main-container {
            padding-top: 45px;
            position: relative;
            height: calc(100%);
            margin-left: 17.5%;
            margin-top: 60px;
        }

        .modal-dialog {
            z-index: 9999999;
        }

        @media (min-width: 768px) {
            .modal-content {
                -webkit-box-shadow: 0 5px 15px rgba(0, 0, 0, .5);
                box-shadow: 0 -2px 20px rgba(0, 0, 0, .5) !important;
            }
        }

        td {
            cursor: default;
        }

        /*个数*/
        #banjieNum {
            background-color: #d15b47 !important;
            margin: 10px 3px;
            color: #fff;
            position: absolute;
            top: -15px;
            right: -17px;
        }

        .project_detail_css {
            position: absolute;
            top: -36px;
            right: 20px;
            border: 1px solid #aaa;
            padding: 1px 5px;
        }

        .pdd {
            margin: 5px 0px;
        }

        .ppdd {
            margin: 0px;
        }
    </style>
</head>
<body class="bgcolor">
<%--上传成功模态框--%>
<div class="shade" style="display: none;"></div>
<div class="warning" style="display: none;">
    <p class="title"><em></em><span class="close">X</span></p>
    <p class="cont"></p>
    <div class="la-square-jelly-box la-3x">
        <div></div>
        <div></div>
    </div>
</div>
<%@ include file="/WEB-INF/views/modules/commons/nav.jsp" %>
<%@ include file="/WEB-INF/views/modules/commons/menu.jsp" %>
<!-- /section:basics/navbar.layout -->
<table></table>
<div class="main-container" id="main-container">
    <!-- /section:basics/sidebar -->
    <div class="main-content">
        <div class="row search-row" style="margin-top: 0px; margin-left: 5px !important;">
            <div class="col-xs-2">
                <input type="text" class="input-sm form-control" id="searchWord" placeholder="请输入要搜索的关键词"/>
            </div>
            <div class="col-xs-5" style="right: 35px;">
                <div class="col-xs-12">
                    <button class="btn btn-sm btn-success" id="query">搜索单位</button>
                    <button class="btn btn-sm btn-primary" id="ownerUnit">业主单位</button>
                    <button class="btn btn-sm btn-primary" id="approvalDepartment">审批单位</button>
                    <button class="btn btn-sm btn-primary" id="supervisionDepartment">督查单位</button>
                    <%--<button class="btn btn-sm btn-default clickMe" id="more">更多 ></button>--%>
                </div>
            </div>
            <div id="more_show" class="col-xs-4 pull-right" style="right: 20px;">
                <div class="pull-right">
                    <button class="btn btn-sm btn-success" id="queryUser">查询用户</button>
                    <button class="btn btn-sm btn-success" id="queryRole">查询角色</button>
                    <button class="btn btn-sm btn-primary" id="addDept">添加单位</button>
                </div>
            </div>
        </div>
        <div class="main-content-inner">
            <div class="page-content">
                <!-- /section:settings.box -->
                <div class="row" style="position: static">
                    <div class="col-xs-12" style="margin: 5px 0px;">
                        <div class="pull-left">
                        </div>
                        <div class="pull-right">
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-xs-12">
                        <!-- PAGE CONTENT BEGINS -->
                        <!-- jqGrid表格 -->
                        <table id="gridTable"></table>
                        <!-- jqGrid工具类 -->
                        <div id="gridPager"></div>
                        <!-- 查询对话框 -->
                        <div style="display: none;">
                            <div class="row" id="queryDialog"></div>
                        </div>
                        <!-- PAGE CONTENT ENDS -->
                    </div><!-- /.col -->
                </div><!-- /.row -->
                <div class="row" style="margin-left: 2px;">
                    <%--* 双击列表进行更多操作--%>
                </div>
            </div><!-- /.page-content -->
        </div>
    </div><!-- /.main-content -->
    <a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
        <i class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i>
    </a>

</div><!-- /.main-container -->
</div>
<!-- footer -->
<script src="<s:url value="/assets/web/js/jquery.min.js?v=2.1.4"></s:url>"></script>
<%--公用js--%>
<script src="<s:url value="/assets/web/js/commo.js"></s:url>"></script>
<link rel="stylesheet" href="<s:url value="/assets/web/css/login/bootstrap.min.css?v=3.3.6"></s:url>">
<script src="<s:url value="/assets/web/js/jqpaginator.min.js"></s:url>"></script>
<script src="<s:url value="/assets/web/js/baseAPI.js"></s:url>"></script>
<%--多选js--%>
<script src="<s:url value="/assets/web/js/multiSelect/js/fselect.js"></s:url>"></script>
<script src="<s:url value="/assets/web/common/bootstrapvalidator/dist/js/bootstrapValidator.js"></s:url>"></script>
<%@ include file="/WEB-INF/views/include/footer.jsp" %>
<!-- dialog -->
<%@ include file="/WEB-INF/views/include/dialog.jsp" %>


<script type="text/javascript">
    //基本路径
    var baseUrl = "<s:url value="/deptManageSuper"></s:url>/";
    //jqgrid的表格高度
    var height = 320;
    //jqgrid表格行头的中文
    var colNames = [
        '', '单位名称', '单位类型', '操作'
    ];
    var colModel = [
        {name: 'sysId', index: 'sysId', hidden: true, editable: true, key: true},
        {name: 'deptName', index: 'deptName', editable: true},
        {name: 'typeName', index: 'typeName', editable: true},
        {name: 'deptType', index: 'deptType', editable: true, formatter: branchTypeFmatter}
    ];

    //jqgrid的具体执行方法
    jqgrid({
        autoScroll: false,
        shrinkToFit: true,
        gridTableId: "#gridTable",
        gridPagerId: "#gridPager",
        onSelectRow: function (rowid, status) {
            if (!status) {
                gridRemoveSelect(rowid);
            } else {
                var flag = false;
                for (var i = 0; i < rowids.length; i++) {
                    if (rowids[i] == rowid) {
                        flag = true;
                        continue;
                    }
                }
                if (!flag) {
                    gridAddSelect(rowid);
                }
            }
        },
        gridComplete: function () {
            var rowIds = jQuery("#gridTable").jqGrid('getDataIDs');
            for (var k = 0; k < rowIds.length; k++) {
                var flag = false;
                for (var i = 0; i < rowids.length; i++) {
                    if (rowids[i] == rowIds[k]) {
                        flag = true;
                        continue;
                    }
                }
                if (flag && flag == true) {
                    jQuery("#gridTable").setSelection(rowIds[k], true);
                }
            }
        }
    });
    //清空选中行
    $("#cancelChecked").click(function () {
        $("#gridTable").jqGrid('resetSelection');
        rowids = [];
    });
    var rowids = [];//选中行id
    /**
     * 取消选中
     */
    function gridRemoveSelect(rowid) {
        rowids.remove(rowid);
    }

    /**
     * 添加选中
     */
    function gridAddSelect(rowid) {
        rowids.push(rowid);
    }

    /**
     * 重写Array
     */
    Array.prototype.remove = function (val) {
        var index = this.indexOf(val);
        if (index > -1) {
            this.splice(index, 1);
        }
    };
    /**
     * 重写Array
     */
    Array.prototype.indexOf = function (val) {
        for (var i = 0; i < this.length; i++) {
            if (this[i] == val) return i;
        }
        return -1;
    };
    //开启冻结列
    $("#gridTable").jqGrid('setFrozenColumns');

    //重置表单
    function reset() {
        resetForm("#formDialog form");
    }

    function branchTypeFmatter(cellvalue, options, rowObject) {
        var deptName = rowObject.deptName;
        var sysId = options.rowId;
        var detailBtn = "<div style='margin:0px; '><button title='查看用户' class=\"btn btn-sm btn-primary\" style='width: 75px; margin: 0 5px;'  onclick=\"queryUserDetail('" + deptName + "'); \">查看用户</button>" +
            "<button title='修改单位' class=\"btn btn-sm btn-primary\" style='width: 75px; margin: 0 5px;'  onclick=\"editDeptDetail('" + sysId + "'); \">修改</button>" +
            "<button title='删除单位' class=\"btn btn-sm btn-primary\" style='width: 75px; margin: 0 5px;'  onclick=\"queryUserDetail('" + sysId + "'); \">删除</button></div>";
        return detailBtn;
    }

    function queryUserDetail(dept) {
        var url = "/userManageSuper?branch=" + Trim(dept);
        window.location.href = url;
    }

    function Trim(str) {
        return str.replace(/(^\s*)|(\s*$)/g, "");
    }

    //业主单位
    $("#ownerUnit").click(function () {
        var url = '/deptManageSuper';
        //先清空条件,多次调用时查询条件会累加
        $('#gridTable').jqGrid('clearGridData');
        $("#gridTable").jqGrid('setGridParam', {
            url: url,
            datatype: 'json',
            postData: {'deptType': "0"}, //发送数据
            page: 1
        }).trigger("reloadGrid"); //重新载入
    });

    //审批单位
    $("#approvalDepartment").click(function () {
        var url = '/deptManageSuper';
        //先清空条件,多次调用时查询条件会累加
        $('#gridTable').jqGrid('clearGridData');
        $("#gridTable").jqGrid('setGridParam', {
            url: url,
            datatype: 'json',
            postData: {'deptType': "1"}, //发送数据
            page: 1
        }).trigger("reloadGrid"); //重新载入
        var userType = ${user.branchType};
    });

    //督查组
    $("#supervisionDepartment").click(function () {
        var url = '/deptManageSuper';
        //先清空条件,多次调用时查询条件会累加
        $('#gridTable').jqGrid('clearGridData');
        $("#gridTable").jqGrid('setGridParam', {
            url: url,
            datatype: 'json',
            postData: {'deptType': "4"}, //发送数据
            page: 1
        }).trigger("reloadGrid"); //重新载入
    });


    var exportData = '';
    //显示查询对话框
    var queryDialog = $("#queryDialog");

    $(function () {

        //显示隐藏
        /*
        $(".clickMe").click(function () {
            if ($(this).text() === "更多 >") {
                $("#more_show").show(100);
                $(this).text("收起 <")
            } else if ($(this).text() === "收起 <") {
                $("#more_show").hide(100);
                $(this).text("更多 >");
            }
        });
        */

        //不同用户显示不通按钮
        var userType = ${user.branchType};
        var userRole = "${user.role}";
        if (userRole == "责任人") {
        } else {
            if (userType == "4") {
            }
            if (userType == "1") {
            }
            if (userType == "0") {
            }
            //管理员菜单
            if (userType == "2") {
                $(".project_detail_css").css("display", "inline");
            }
        }
    });

    //最新搜索
    $("#query").click(function () {
        var url = '/deptManageSuper';
        var searchWord = $("#searchWord").val();
        //先清空条件,多次调用时查询条件会累加
        $('#gridTable').jqGrid('clearGridData');
        $("#gridTable").jqGrid('setGridParam', {
            url: url,
            datatype: 'json',
            postData: {'searchWord': searchWord}, //发送数据
            page: 1
        }).trigger("reloadGrid"); //重新载入
    });
    //∨∨∨∨∨∨∨∨∨∨∨∨∨∨∨∨∨∨∨∨∨单位∨∨∨∨∨∨∨∨∨∨∨∨∨∨∨∨∨∨∨∨∨
    //添加单位
    $("#addDept").click(function () {
        loadDialog({
            dialogTitle: '添加单位',
            dialogUrl: getUrl("createDept"),
            dialogFoot: '<button id="submit" type="button" class="btn btn-primary" onclick="createDept()">确认</button>' +
                '<button type="button" class="btn btn-pink" onclick="reset()">重置</button>' +
                '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>'
        });
    });
    function createDept() {
        var typeName = $("#typeName_select").val();
        if (typeName != "") {
            executeSaveOrUpdate({
                formId: "#formDialog form",
                dialogId: "#formDialog",
                url: getUrl("createDept"),
                tableId: "#gridTable",
                successMessage: "单位添加成功",
                successTitle: '保存对话框',
                //failMessage: '保存失败',
                failTitle: '消息对话框'
            });
            // 倒计时
            var btn = document.getElementById("submit");
            btn.disabled = true;
            countdown(5);
        } else {
            alert("单位类型未选择");
        }
    }
    //修改单位，弹出修改框
    function editDeptDetail(deptSysId) {
        var url = "/deptManageSuper/editDept?sysId=" + deptSysId;
        loadDialog({
            dialogTitle: '修改单位',
            dialogUrl: url,
            dialogFoot: '<button id="submit" type="button" class="btn btn-primary" onclick="editDept()">确认</button>' +
                '<button type="button" class="btn btn-pink" onclick="reset()">重置</button>' +
                '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>'
        });
    }
    function editDept() {
        var typeName = $("#typeName_select").val();
        if (typeName != "") {
            executeSaveOrUpdate({
                formId: "#formDialog form",
                dialogId: "#formDialog",
                url: getUrl("editDept"),
                tableId: "#gridTable",
                successMessage: "单位修改成功",
                successTitle: '保存对话框',
                //failMessage: '保存失败',
                failTitle: '消息对话框'
            });
            // 倒计时
            var btn = document.getElementById("submit");
            btn.disabled = true;
            countdown(5);
        } else {
            alert("单位类型未选择");
        }
    }
    //∧∧∧∧∧∧∧∧∧∧∧∧∧∧∧∧∧∧∧∧∧单位∧∧∧∧∧∧∧∧∧∧∧∧∧∧∧∧∧∧∧∧∧

    //∨∨∨∨∨∨∨∨∨∨∨∨∨∨∨∨∨∨∨∨∨角色∨∨∨∨∨∨∨∨∨∨∨∨∨∨∨∨∨∨∨∨∨
    //查询角色
    $("#queryRole").click(function () {
        window.location.href = '/roleManageSuper';
    })
    //∧∧∧∧∧∧∧∧∧∧∧∧∧∧∧∧∧∧∧∧∧角色∧∧∧∧∧∧∧∧∧∧∧∧∧∧∧∧∧∧∧∧∧

    //∨∨∨∨∨∨∨∨∨∨∨∨∨∨∨∨∨∨∨∨∨用户∨∨∨∨∨∨∨∨∨∨∨∨∨∨∨∨∨∨∨∨∨
    //查询用户
    $("#queryUser").click(function () {
        window.location.href = '/userManageSuper';
    })

</script>

</body>
</html>